import playground from './modules/playground'
import frame from './modules/frame'
import d2Crud from './modules/d2-crud'
import plugins from './modules/plugins'
import charts from './modules/charts'
import components from './modules/components'
import element from './modules/element'
import business from './modules/business'

import layoutHeaderAside from '@/layout/header-aside'

// 由于懒加载页面太多的话会造成webpack热更新太慢，所以开发环境不使用懒加载，只有生产环境使用懒加载
const _import = require('@/libs/util.import.' + process.env.NODE_ENV)

/**
 * 在主框架内显示
 */
const frameIn = [
  {
    path: '/',
    redirect: { name: 'index' },
    component: layoutHeaderAside,
    children: [
      // 对账单
      {
        path: '/statement',
        name: 'statement',
        meta: {
          auth: true
        },
        component: _import('shop/distribution/statement')
      },
      // 分销规则管理
      {
        path: '/regulation',
        name: 'regulation',
        meta: {
          auth: true
        },
        component: _import('shop/distribution/regulation')
      },
      // 分销员管理
      {
        path: '/distribution',
        name: 'distribution',
        meta: {
          auth: true
        },
        component: _import('shop/distribution/index')
      },
      // 运费管理
      {
        path: '/freight',
        name: 'freight',
        meta: {
          auth: true
        },
        component: _import('shop/freight/index')
      },
      // sku销量详情
      {
        path: '/skuSellCountDetail',
        name: 'skuSellCountDetail',
        meta: {
          auth: true
        },
        component: _import('shop/statistic/skuSellCount/detail')
      },
      // 统计sku销量
      {
        path: '/skuSellCount',
        name: 'skuSellCount',
        meta: {
          auth: true,
          cache: true
        },
        component: _import('shop/statistic/skuSellCount/index')
      },
      // 统计sku浏览量
      {
        path: '/skuBroswerCount',
        name: 'skuBroswerCount',
        meta: {
          auth: true,
          cache: true
        },
        component: _import('shop/statistic/skuBroswerCount/index')
      },
      // 客服
      {
        path: '/kefu',
        name: 'kefu',
        meta: {
          auth: true
        },
        component: _import('shop/kefu/index')
      },
      // 首页轮播图
      {
        path: '/swiper',
        name: 'swiper',
        meta: {
          auth: true
        },
        component: _import('shop/swiper/index')
      },
      // 会员列表
      {
        path: '/membership',
        name: 'membership',
        meta: {
          auth: true
        },
        component: _import('shop/membership/index')
      },
      // 评论列表
      {
        path: '/shop/goods/commentList',
        name: 'commentList',
        meta: {
          auth: true
        },
        component: _import('shop/goods/commentList')
      },
      // 目录管理
      {
        path: '/catalog',
        name: 'catalog',
        meta: {
          auth: true
        },
        component: _import('shop/catalog/index')
      },
      // 订单列表
      {
        path: '/order',
        name: 'order',
        meta: {
          auth: true,
          cache: true
        },
        component: _import('shop/order/index')
      },
      // sku列表
      {
        path: '/shop/goods/skuList',
        name: 'skuList',
        meta: {
          auth: true
        },
        component: _import('shop/goods/skuList')
      },
      // 商品
      {
        path: 'goods',
        name: 'goods',
        meta: {
          auth: true,
          cache: true
        },
        component: _import('shop/goods/index')
      },
      // 供应商
      {
        path: 'supplier',
        name: 'supplier',
        meta: {
          auth: true
        },
        component: _import('shop/supplier')
      },
      // 首页
      {
        path: 'index',
        name: 'index',
        meta: {
          auth: true
        },
        component: _import('system/index')
      },
      // 系统 前端日志
      {
        path: 'log',
        name: 'log',
        meta: {
          title: '前端日志',
          auth: true
        },
        component: _import('system/log')
      },
      // 刷新页面 必须保留
      {
        path: 'refresh',
        name: 'refresh',
        hidden: true,
        component: _import('system/function/refresh')
      },
      // 页面重定向 必须保留
      {
        path: 'redirect/:route*',
        name: 'redirect',
        hidden: true,
        component: _import('system/function/redirect')
      }
    ]
  },
  playground,
  frame,
  d2Crud,
  plugins,
  charts,
  components,
  element,
  business
]

/**
 * 在主框架之外显示
 */
const frameOut = [
  // 登录
  {
    path: '/login',
    name: 'login',
    component: _import('system/login')
  }
]

/**
 * 错误页面
 */
const errorPage = [
  {
    path: '*',
    name: '404',
    component: _import('system/error/404')
  }
]

// 导出需要显示菜单的
export const frameInRoutes = frameIn

// 重新组织后导出
export default [
  ...frameIn,
  ...frameOut,
  ...errorPage
]
